from flask import jsonify
from datetime import datetime

def success_response(data=None, message="操作成功", code=200):
    """成功响应"""
    response = {
        'success': True,
        'message': message,
        'code': code,
        'data': data,
        'timestamp': datetime.utcnow().isoformat()
    }
    return jsonify(response), code

def error_response(message="操作失败", code=400, data=None):
    """错误响应"""
    response = {
        'success': False,
        'message': message,
        'code': code,
        'data': data,
        'timestamp': datetime.utcnow().isoformat()
    }
    return jsonify(response), code

def paginated_response(data, page, per_page, total, message="获取成功"):
    """分页响应"""
    response = {
        'success': True,
        'message': message,
        'code': 200,
        'data': {
            'items': data,
            'pagination': {
                'page': page,
                'per_page': per_page,
                'total': total,
                'pages': (total + per_page - 1) // per_page
            }
        },
        'timestamp': datetime.utcnow().isoformat()
    }
    return jsonify(response), 200 